package view.macrogui
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import model.macro.Territory;
	
	/**
	 */
	public class TerritoryInfo extends Sprite implements SidebarItem
	{
		private var name_field:TextField;
		private var owner_field:TextField;
		private var fortress_field:TextField;
		
		private const TITLE_FORMAT:TextFormat = new TextFormat("Helvetica", 16, 0xFFFFFF);
		private const OWNER_FORMAT:TextFormat = new TextFormat("Helvetica", 13, 0x00DDFF, null, true);
		private const BASIC_FORMAT:TextFormat = new TextFormat("Helvetica", 12, 0xDDDDDD);
		
		public function TerritoryInfo()
		{
			name_field = new TextField();
			name_field.selectable = false;
			name_field.defaultTextFormat = TITLE_FORMAT;
			addChild(name_field);
			
			owner_field = new TextField();
			owner_field.selectable = false;
			owner_field.defaultTextFormat = OWNER_FORMAT;
			addChild(owner_field);
			
			fortress_field = new TextField();
			fortress_field.selectable = false;
			fortress_field.defaultTextFormat = BASIC_FORMAT;
			addChild(fortress_field);
			
			owner_field.y = 16;
			fortress_field.y = owner_field.y + 24;
		}
		
		public function update(territory:Territory):void
		{
			if (territory == null)
			{
				visible = false;
			}
			else
			{
				visible = true;
				name_field.text = territory.name;
				name_field.width = name_field.textWidth + 10;
				fortress_field.text = "" + territory.fortress.toString();
				fortress_field.width = fortress_field.textWidth + 10;
				
				
				if (territory.owner != null)
				{
					OWNER_FORMAT.color = territory.owner.color;
					owner_field.defaultTextFormat = OWNER_FORMAT;
					owner_field.text = territory.owner.name;
					owner_field.width = owner_field.textWidth + 10;
				}
				else
				{
					OWNER_FORMAT.color = 0xDDDDDD;
					owner_field.defaultTextFormat = OWNER_FORMAT;
					owner_field.text = "neutral";
				}
			}
		}
		
		public function getHeight():int
		{
			if (visible)
				return 100;
			else
				return 0;
		}
	
	}

}